//
//  BKRightHeadView.m
//  bestkeep
//
//  Created by utouu_mhm on 16/11/8.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKRightHeadView.h"
#import "masonry.h"

#define RGB(__r, __g, __b)  [UIColor colorWithRed:(1.0*(__r)/255)\
green:(1.0*(__g)/255)\
blue:(1.0*(__b)/255)\
alpha:1.0]

@implementation BKRightHeadView
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self createUI];
    }
    return self;
}

-(void)createUI{
    //底部视图
    UIView *superView = [[UIView alloc]init];
    superView.backgroundColor = [UIColor colorWithRed:225/255.0f green:225/255.0f blue:225/255.0f alpha:0.24];
    [self addSubview:superView];
    [superView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(40.0f);
        make.left.mas_equalTo(self.mas_left);
        make.right.mas_equalTo(self.mas_right);
        make.bottom.mas_equalTo(self.mas_bottom);

    }];
    //文字
    _titleLabel = [[UILabel alloc]init];
    _titleLabel.font = [UIFont systemFontOfSize:15.0];
    _titleLabel.textColor = RGB(102, 102, 102);
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    [superView addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(superView.mas_centerX);
        make.centerY.mas_equalTo(superView.mas_centerY);
        make.height.mas_equalTo(@15);
        make.right.mas_equalTo(self.mas_right).offset(-54);
    }];
    
    //右视图
    UIView *rightView = [[UIView alloc]init];
    rightView.bounds = CGRectMake(0, 0, 54, 40);
    //箭头
    UIImageView *rightImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"TableViewArrow"]];
//    rightView.contentMode = UIViewContentModeScaleAspectFit;
    rightImageView.bounds = CGRectMake(0, 0, 10, 10);
    rightImageView.center = CGPointMake(39, 20);
    [rightView addSubview:rightImageView];
    //更多
    UILabel *rightLabel = [[UILabel alloc]init];
    rightLabel.text = @"更多";
    rightLabel.font = [UIFont systemFontOfSize:12];
    rightLabel.textColor = RGB(178, 178, 178);
    rightLabel.bounds = CGRectMake(0, 0, 25, 11);
    rightLabel.center = CGPointMake(23.0f, 20);
    [rightView addSubview:rightLabel];
    
    //添加手势
    UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickMoreAction:)];
    [rightView addGestureRecognizer:gesture];
    [superView addSubview:rightView];
    [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView.mas_top);
        make.bottom.mas_equalTo(superView.mas_bottom);
        make.right.mas_equalTo(superView.mas_right);
        make.width.mas_equalTo(54);
    }];
    
}

-(void)clickMoreAction:(UITapGestureRecognizer *)sender
{
    if ([self.BKRightHeadViewDelegate respondsToSelector:@selector(BKRightHeadView:clickView:)]) {
        
        [self.BKRightHeadViewDelegate BKRightHeadView:self clickView:sender.view];
    }
}
@end
